package cn.taoticket.controller;

import cn.taoticket.common.Dto;
import cn.taoticket.service.ItemDetailService;
import cn.taoticket.vo.ItemDetailVo;
import cn.taoticket.vo.ItemPriceVo;
import cn.taoticket.vo.ItemSchedulerVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 商品详情界面Controller
 */
@RestController
@RequestMapping(value = "/api")
public class ItemDetailController {
    @Autowired
    private ItemDetailService itemDetailService;
    /**
     * 根据id查询商品
    *这里路径中的p代表直接pass的请求，如果不是p是v代表需要校验
     */
    @RequestMapping(value = "/p/queryItemDetail", method = RequestMethod.POST)
    public Dto<ItemDetailVo> queryItemDetail(@RequestBody Map<String, Object> param) throws Exception {
        String id = param.get("id").toString();
//        LogUtils.i(Constants.TOPIC.ITEM_CONSUMER, "查询商品id为" + id + "的信息");
        return itemDetailService.queryItemDetail(Long.parseLong(id));
    }

    /**
     * 根据商品id查询排期

     */
    @RequestMapping(value = "/p/queryItemScheduler",method = RequestMethod.POST)
    public Dto<List<ItemSchedulerVo>> queryItemScheduler(@RequestBody Map<String, Object> param) throws Exception {
        String itemId = param.get("itemId").toString();
        return itemDetailService.queryItemScheduler(Long.parseLong(itemId));
    }

    /**
     * 根据商品排期查询商品价格
     *
     */
    @RequestMapping(value = "/p/queryItemPrice",method = RequestMethod.POST)
    public Dto<List<ItemPriceVo>> queryItemPrice(@RequestBody Map<String, Object> param) throws Exception {
        String scheduleId = param.get("scheduleId").toString();
        return itemDetailService.queryItemPrice(Long.parseLong(scheduleId));
    }
}

